#include "system.h"


//extern const DY_HAL DYUAV_HAL;
extern bool _dy_thread_should_exit;
void _system_init();
uint32_t _micros();
uint32_t _millis();
uint64_t _micros64();
uint64_t _millis64();

void _system_init(){
}

void _panic(const char *errormsg, ...){
//    pilot_err("%s\n", errormsg);
//    return;
//    va_list ap;
//
//    va_start(ap, errormsg);
//    vdprintf(1, errormsg, ap);
//    va_end(ap);
//    write(1, "\n", 1);
//
//    hal.scheduler->delay_microseconds(10000);
//    _dy_thread_should_exit = true;
//    exit(1);
}

uint32_t _micros(){
    return _micros64() & 0xFFFFFFFF;
}

uint32_t _millis(){
    return _millis64() & 0xFFFFFFFF;
}

uint64_t _micros64(){
    return (uint64_t)hrt_absolute_time();
}

uint64_t _millis64(){

    return _micros64() / 1000;
}

void system_constructs(system_t *instance){
	instance->micros = _micros;
	instance->micros64 = _micros64;
	instance->millis = _millis;
	instance->millis64 = _millis64;
	instance->panic = _panic;
	instance->system_init = _system_init;

}
